package com.journey.org.app

import com.journey.org.entity.*
import com.mvvmhabit.org.http.RetrofitManager
import com.mvvmhabit.org.utils.DeferredUtil
import retrofit2.http.HTTP

class RequestHttpManager {

    suspend fun loadPlayAndroidBannerList(): PlayAndroidResponse<List<PlayAndroidBannerEntity>>? {
        return DeferredUtil.requests(
            RetrofitPlayAndroidManager.getInstance()?.create(API::class.java)
                ?.loadPlayAndroidBannerListAsync()!!
        )
    }

    // 登录
    suspend fun login(params: HashMap<String, Any>): BaseResponse<LoginEntity> {
        val loginEntity: LoginEntity? = DeferredUtil.requests(
            RetrofitManager.getInstance()?.create(API::class.java)
                ?.loginAsync(params)!!
        )
        val baseResponse = BaseResponse<LoginEntity>()
        baseResponse.data = loginEntity!!
        baseResponse.code = loginEntity.code
        baseResponse.msg = loginEntity.msg
        return baseResponse
    }

    // 获取文章列表数据
    suspend fun loadArticleList(params: HashMap<String, Any>): BaseResponse<List<ArticleEntity>>? {
        return DeferredUtil.requests(
            RetrofitManager.getInstance()?.create(API::class.java)
                ?.loadArticleListAsync(params)!!
        )
    }

    // 获取收藏列表
    suspend fun loadCollectionList(params: HashMap<String, Any>): BaseResponse<List<MineCollectionEntity>>? {
        return DeferredUtil.requests(
            RetrofitManager.getInstance()?.create(API::class.java)
                ?.loadCollectionListAsync(params)!!
        )
    }

    // 获取收藏详情
    suspend fun loadCollectionDetailById(params: HashMap<String, Any>): BaseResponse<MineCollectionEntity>? {
        return DeferredUtil.requests(
            RetrofitManager.getInstance()?.create(API::class.java)
                ?.loadCollectionDetailByIdAsync(params)!!
        )
    }

    // 获取账号详情
    suspend fun loadAccountList(params: HashMap<String, Any>): BaseResponse<List<MineAccountEntity>>? {
        return DeferredUtil.requests(
            RetrofitManager.getInstance()?.create(API::class.java)
                ?.loadAccountListAsync(params)!!
        )
    }
}


inline fun requestHttpManager(buildRequest: RequestHttpManager.() -> Unit) {
    RequestHttpManager().apply(buildRequest)
}